<?php
    // +----------------------------------------------------------------------
    // | 功能说明"
    // +----------------------------------------------------------------------
    // | Copyright (c) 2016~2030 http://www.jmzh1688.com All rights reserved.
    // +----------------------------------------------------------------------
    // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------
    // | Author: lxl
    // | jmzhfsauto
    // +----------------------------------------------------------------------
    namespace app\admin\model;
    use Think\Db;
    use think\Model;
    class AdminModel extends Model {
        protected $name = 'admin_hcly';
        protected $autoWriteTimestamp = true; //时间自动更新 create_time ,update_time
        protected $field = true;
        public $title = '名称';
        public function edit($param) {
            try {
                $result = $this->update($param);
                if (false === $result) {
                    return msg(-1, '', $this->getError());
                } else {
                    return msg(1, url('admin/index'), '修改耗材领用用户成功');
                }
            }
            catch(PDOException $e) {
                return msg(-2, '', $e->getMessage());
            }
        }
        public function add($param) {
            try {
                $param['isdelete'] = 0;
                $result = $this->save($param);
                if (false === $result) {
                    return msg(-1, '', $this->getError());
                } else {
                    return msg(1, url('admin/index'), '添加耗材领用用户成功');
                }
            }
            catch(PDOException $e) {
                return msg(-2, '', $e->getMessage());
            }
        }
        public function getById($id) {
            return $this->where('id', $id) ->find();
        }
        public function delById($id) {
            try {
                $this->where('id', $id) ->update(['isdelete'=>'1']);
                return msg(1, '', '删除成功');
            }
            catch(PDOException $e) {
                return msg(-1, '', $e->getMessage());
            }
        }
        public function getByWhere($where, $offset, $limit, $whereor = '') {
            return $this->where($where) ->where($whereor) ->limit($offset, $limit) ->order('id desc') ->select();
        }
        public function getAllCount($where, $whereor = '') {
            return $this->where($where) ->where($whereor) ->count();
        }
        //获取当前模型数据表
        public function getTable() {
            return $this->name;
        }
        /**/
    }
    